home *** CD-ROM | disk | FTP | other *** search
/ Magazyn WWW 1999 June / magazyn_www_no26_06_1999.iso / prog / mac / nihimage / nihimage.hqx / NIH Image 1.61 / Macros / Movie Making < prev    next >
Text File  |  1996-09-30  |  11KB  |  391 lines

  1. procedure DeInterlace(OddSlice: boolean);
  2. {
  3. If OddSlice is true, each even line is replaced by the adjacent odd line, otherwise each odd line is replaced by the adjacent even line.
  4. }
  5. var
  6.   i,width,height,row1,row2:integer;
  7. begin
  8.   GetPicSize(width,height);
  9.   if OddSlice then begin
  10.      i := 1;
  11.      while i < (height - 2) do begin
  12.         GetRow(0, i, width);
  13.         PutRow(0, i - 1, width);
  14.         i := i + 2;
  15.      end;
  16.   end else begin
  17.      i := 0;
  18.      while i < (height - 1) do begin
  19.         GetRow(0, i, width);
  20.         PutRow(0, i + 1, width);
  21.         i := i + 2;
  22.      end;
  23.   end;
  24. end;
  25.  
  26. macro 'De-interlace Stack';
  27. {Converts 30fps movies to 60 fields per second.}
  28. var
  29.   i, width, height:integer;
  30. begin
  31.   RequiresVersion(1.61);
  32.   if nSlices=0 then
  33.     exit('Stack required.');
  34.   i:=nSlices;
  35.   GetPicSize(width,height);
  36.   if (i * width * height) > get('freemem') then
  37.     exit('There is not enough free RAM to de-interlace this stack.');
  38.   repeat
  39.      SelectSlice(i);
  40.      SelectAll;
  41.      Copy;
  42.      AddSlice;
  43.      Paste;
  44.      i:=i - 1;
  45.   until i = 0;
  46.   KillRoi;
  47.   for i := 1 to nSlices do begin
  48.      SelectSlice(i);
  49.      DeInterlace(odd(i));
  50.   end;
  51. end;
  52.  
  53.  
  54. macro 'Make Movie to Disk╔';
  55. {
  56. Captures images at a specified rate and saves them to disk.
  57. Select an area of interest within the Camera window before
  58. starting. Abort at any time by pressing the mouse button.
  59. }
  60. var
  61.   nFrames,n,Left,Top,Width,Height:integer;
  62.   interval,EndTicks,secs:integer;
  63.   FirstTime:boolean;
  64. begin
  65.   GetRoi(Left,Top,Width,Height);
  66.   if width=0 then begin
  67.      PutMessage('First select the area of interest in the Camera window.');
  68.      exit;
  69.   end;
  70.   nFrames:=GetNumber('Number of Frames?',10);
  71.   secs:=GetNumber ('Interval Between Frames (seconds)?',60.0);
  72.   interval:=round(secs*60);
  73.   FirstTime:=true;
  74.   for n:=1 to nFrames do begin
  75.       StopCapturing;
  76.        beep;
  77.        MakeRoi(Left,Top,Width,Height);
  78.        SaveAs('Frame ',n);
  79.       if FirstTime then begin
  80.           EndTicks:=TickCount+interval;
  81.           FirstTime:=false;
  82.       end;
  83.       if button then begin
  84.          StopCapturing;
  85.          exit;
  86.       end;
  87.       StartCapturing;
  88.       while TickCount < EndTicks do begin
  89.           secs:=(EndTicks - TickCount) div 60;
  90.           ShowMessage(n:1, '/', nFrames,' ', secs:4)
  91.       end;
  92.       EndTicks:=EndTicks+interval;
  93.   end;
  94.   StopCapturing;
  95. end;
  96.  
  97.  
  98. macro 'Capture Averaged to Stack╔';
  99. var
  100.   x,y,i,s,f,t,width,height:integer;
  101.   camera, stack, avg, nFrames:integer;
  102. begin
  103.   nFrames:=GetNumber('Number of frames to capture:', 10);
  104.   SelectWindow('Camera');
  105.   camera:=PidNumber;
  106.   GetRoi(x,y,width,height);
  107.    if width=0 then begin
  108.     PutMessage('Rectangular selection required.');
  109.     exit;
  110.   end;
  111.   SetNewSize(width,height);
  112.   MakeNewStack('Stack');
  113.   stack:=PidNumber;
  114.   s:=TickCount;
  115.   for i:= 1 to nFrames do begin
  116.      ChoosePic(Camera);
  117.      MakeRoi(x,y,width,height);
  118.      AverageFrames;
  119.      RestoreRoi;
  120.      Copy;
  121.      ChoosePic(stack);
  122.      if i>1 then AddSlice;
  123.      Paste;
  124.   end;
  125.   f:=TickCount;
  126.   KillRoi;
  127.   SelectSlice(1);
  128.   t:=(f-s)/60;
  129.   ShowMessage('Time = ', t:1:2, ' seconds');
  130.   exit;
  131.   AverageSlices;
  132.   avg:=PidNumber;
  133.   SelectPic(stack);
  134.   Dispose;
  135.   SelectPic(avg);
  136. end;
  137.  
  138. procedure PlotFrameIntervals(nFrames: integer);
  139. var
  140.    xmin,xmax,ymin,ymax,i,xscale,yscale,yscale2:real;
  141.    width,height,margin,pwidth,pheight:integer;
  142.    x,y,pbottom,yinc:integer;
  143.    minInterval,maxInterval,offset:real;
  144.    interval,reqInterval,avgInterval,ElapsedTime:real;
  145.    TotalTime:real;
  146. begin
  147.   RequiresVersion(1.58);
  148.   SaveState;
  149.   margin:=40;
  150.   width:=500;
  151.   height:=300;
  152.   ymin:=999999;
  153.   ymax:=-999999;
  154.   ElapsedTime := PlotData[nFrames];
  155.   reqInterval := PlotData[nFrames+1];
  156.   avgInterval := ElapsedTime / (nFrames -1);
  157.   TotalTime := avgInterval * nFrames;
  158.   for i:=1 to nFrames -1 do begin
  159.       interval := PlotData[i+1]-PlotData[i];
  160.       if interval<ymin then ymin:=interval;
  161.       if interval>ymax then ymax:=interval;
  162.   end;
  163.   minInterval:=ymin;
  164.   maxInterval:=ymax;
  165.   ymin:=0;
  166.   xmin:=1;
  167.   xmax:=nFrames-1;
  168.   SetNewSize(width,height);
  169.   SetForeground(255);
  170.   SetBackground(0);
  171.   MakeNewWindow('Frame Intervals (seconds)');
  172.   pwidth:=width-margin-130;
  173.   pheight:=height-2*margin;
  174.   pbottom:=margin+pheight;
  175.   xscale:=pwidth/xmax;
  176.   yscale:=pheight/ymax;
  177.   yscale2:=pheight/(PlotData[nFrames]);
  178.   SetForeground(255);
  179.   SetBackground(0); 
  180.   SetLineWidth(1);
  181.   for i:=2 to nFrames do begin
  182.      interval := PlotData[i]-PlotData[i-1];
  183.      x:=margin+(i-1)*xscale;
  184.      y:=pbottom-interval*yscale;
  185.      MoveTo(x, pBottom);
  186.      LineTo(x,y);
  187.      MoveTo(margin+(i-2)*xscale, pBottom-(PlotData[i-1])*yscale2);
  188.      LineTo(margin+(i-1)*xscale, pBottom-(PlotData[i])*yscale2);
  189.   end;
  190.   KillRoi;
  191.   MoveTo(margin, margin);
  192.   LineTo(margin, margin+pheight);
  193.   LineTo(margin+pwidth, margin+pheight);
  194.   SetFont('Geneva');
  195.   SetFontSize(9);
  196.   SetText('Right Justified');
  197.   MoveTo(margin-2, margin+pheight-5);
  198.   writeln(ymin:1:3);
  199.   MoveTo(margin-2, margin);
  200.   writeln(ymax:1:3);
  201.   SetText('Left Justified');
  202.   x := margin+pwidth+10;
  203.   y := margin;
  204.   yinc := 12;
  205.   MoveTo(x, y);
  206.   writeln('frames=', nFrames:1);
  207.   y := y+yinc;
  208.   MoveTo(x, y);
  209.   writeln('expected time=', nFrames*reqInterval:1:4);
  210.   y := y+yinc;
  211.   MoveTo(x, y);
  212.   writeln('actual time=', TotalTime:1:4);
  213.   y := y+yinc;
  214.   MoveTo(x, y);
  215.   writeln('req. interval=', reqInterval:1:4);
  216.   y := y+yinc;
  217.   MoveTo(x, y);
  218.   writeln('avg interval=', avgInterval:1:4);
  219.   y := y+yinc;
  220.   MoveTo(x, y);
  221.   writeln('min interval=', minInterval:1:4);
  222.   y := y+yinc;
  223.   MoveTo(x, y);
  224.   writeln('max interval=', maxInterval:1:4);
  225.   y := y+yinc;
  226.   MoveTo(x, y);
  227.   if reqInterval <> 0.0 then
  228.      writeln('expected rate=', 1/reqInterval:1:3,' fps');
  229.   y := y+yinc;
  230.   MoveTo(x, y);
  231.   writeln('actual rate=', (nFrames)/TotalTime:1:3,' fps');
  232.  RestoreState;
  233. end;
  234.  
  235. macro 'Make Movie and Plot Intervals [M]';
  236. var
  237.   i, nFrames, x, y, w, h: integer;
  238.   avgInterval: real;
  239. begin
  240.   GetRoi(x, y, w, h);
  241.   if w = 0 then begin
  242.      PutMessage('Selection Required.');
  243.      exit;
  244.   end;
  245.   MakeMovie('dialog, time-stamp', -1, -1);
  246.   nFrames := PlotData[0];
  247.   PlotFrameIntervals(nFrames); 
  248. end;
  249.  
  250.  
  251. Macro 'Frame Rate vs. Frame Size';
  252. var
  253.   n, i, width, height,w,h:integer;
  254.   TextWidth, TextHeight: integer;
  255.   avgFrameInterval: real;
  256. begin
  257.    RequiresVersion(1.61);
  258.    n := 50;
  259.    TextWidth := 150;
  260.    TextHeight := 400;
  261.    StartCapturing;
  262.    GetPicSize(width, height);
  263.    SaveState;
  264.    SetFont('Monaco');
  265.    SetFontSize(9);
  266.    NewTextWindow('Rate vs. Size', TextWidth, TextHeight);
  267.    MoveWindow(get('ScreenWidth') - TextWidth - 10, 50);
  268.    for i := 1 to n do begin
  269.      SelectWindow('Camera');
  270.      w := round(width*(i/n));
  271.       h := round(height*(i/n));
  272.       w := w - (w mod 4);
  273.       h := h - (h mod 4);
  274.      MakeRoi(0, 0, w, h);
  275.      MakeMovie('blind', 10, 0);
  276.      avgFrameInterval := GetSliceSpacing;
  277.      Dispose;
  278.      SelectWindow('Rate vs. Size');
  279.      writeln(i:3, avgFrameInterval:6:3, '  ', w:1:0, 'x', h:1:0);
  280.   end;
  281.   RestoreState;
  282. end;
  283.  
  284.  
  285. macro 'Add Timestamps to Stack...';
  286. {By Steve Potter (spotter@gg.caltech.edu).  Adds a timestamp to each frame of a
  287. stack of time-lapse images.}
  288.  
  289. var
  290.   i,j,k,interval, frameNumber, hours, minutes, seconds, xpos, ypos, colon1pos,
  291. colon2pos, ones, tens: integer;
  292.   militaryTime, printSeconds: boolean;
  293.   StartTime, name, textStamp,tempStr, hourStr, minStr, secStr, AMPMstr, timeStr,
  294. oneStr, tenStr: string;
  295.  
  296. begin
  297.   if nSlices=0 then begin
  298.     PutMessage('Stack required.');
  299.     exit
  300.   end;
  301.   ShowMessage('Time Stamps:\\Make sure you have already selected the desired font, fontsize, and drawcolor.\Use AM or PM if 12-h clock is desired, e.g. "3:07 PM".  Use two colons if you wish to display seconds, e.g. "3:07:22 PM".\The point you click will be the upper-left corner of the time-stamp.');
  302.   interval:=GetNumber('Time interval (seconds): ',300);
  303.   StartTime:=GetString('Enter the start time.  ','0:00:00');
  304.   MilitaryTime:=true;
  305.   AMPMstr:='';
  306.   if (pos('AM',StartTime)<>0) then MilitaryTime:=false;
  307.   if (pos('AM',StartTime)<>0) then AMPMstr:=' AM';
  308.   if (pos('PM',StartTime)<>0) then MilitaryTime:=false;
  309.   if (pos('PM',StartTime)<>0) then AMPMstr:=' PM';
  310.  
  311.   hourStr:=StartTime;
  312.   colon1pos:=pos(':', StartTime);
  313.   Delete(hourStr,colon1pos, 10); {get rid of everything but the hours}
  314.   hours:=StringToNum(hourStr);
  315.   minStr:=StartTime;
  316.   Delete(minStr, 1, colon1pos);  {remove the hours}
  317.   colon2pos:=pos(':',minStr);
  318.   if (colon2pos<>0) then printSeconds:=true else printSeconds:=false;
  319.   Delete(minStr,3, 7);  {get rid of everything but the minutes}
  320.   minutes:=StringToNum(minStr);
  321.   seconds:=0;
  322.  If printSeconds then
  323.  begin
  324.   secStr:=StartTime;
  325.   Delete(secStr,1, colon2pos);
  326.   Delete(secStr,3, 5);   {get rid of all but the seconds}
  327.   seconds:=StringToNum(secStr);
  328.  end;
  329.  
  330.   frameNumber:=GetNumber('Enter the number of the first frame:',1);
  331.   name:=GetString('Enter your name or initials: ');
  332.   textStamp:=GetString('Date, experimental conditions, etc.: ','');
  333.   PutMessage('Click at desired text location...');
  334.   SelectSlice(1);
  335.   repeat
  336.     GetMouse(xpos,ypos);
  337.   until Button;
  338.   For i:=1 to nSlices do
  339.   begin
  340.      SelectSlice(i);
  341.      MoveTo(xpos,ypos);
  342.      ones:=minutes mod 10;
  343.      oneStr:=chr(ones+48); {48 is the ASCII value of the character 0}
  344.      tens:=minutes div 10;
  345.      tenStr:=chr(tens+48);
  346.      minStr:=concat(tenStr, oneStr); {it is a shame I cant find a num-2-string function!}
  347.      if printSeconds then
  348.       begin
  349.        ones:=seconds mod 10;
  350.        oneStr:=chr(ones+48); {48 is the ASCII value of the character 0}
  351.        tens:=seconds div 10;
  352.        tenStr:=chr(tens+48);
  353.        secStr:=concat(tenStr, oneStr);
  354.       end;
  355.      timeStr:=concat(hours,':',minStr);
  356.      if printSeconds then timeStr:=concat(timeStr, ':',secStr);
  357.      Writeln(textStamp,'    ',name);
  358.      Write(frameNumber, '    ',timeStr, AMPMstr);
  359.      frameNumber:=frameNumber+1;
  360.      seconds:=seconds+interval;
  361.      minutes:=minutes+(seconds div 60);
  362.      seconds:=seconds mod 60;
  363.      hours:=hours +(minutes div 60);
  364.      minutes:=minutes mod 60;
  365.      if militaryTime then if (hours>24) then hours:=hours-24;
  366.      if ((not(militaryTime)) AND (hours>11)) then
  367.        begin
  368.          if (AMPMstr=' AM') then AMPMstr:= ' PM';
  369.          if (AMPMstr=' PM') then AMPMstr:= ' AM';
  370.        end;
  371.       if ((not(militaryTime)) AND (hours>12)) then hours:=hours-12;
  372.   end;
  373. end; {Time Stamps...}
  374.  
  375.  
  376. macro 'Projection Example';
  377. begin
  378.    SetProjection('Initial Angle', 0);
  379.    SetProjection('Total Rotation', 360);
  380.    SetProjection('Rotation Increment', 30);
  381.    SetDensitySlice(0, 254);   {sets transparency bounds}
  382.    SetProjection('Surface Opacity', 50);
  383.    SetProjection('Surface Depth-Cueing', 50);
  384.    SetProjection('Interior Depth-Cueing', 50);
  385.    SetProjection('Save Projections', false);
  386.    SetProjection('Minimize Size', true);
  387.    SetProjection('Y-Axis');
  388.    SetProjection('Brightest Point');
  389.    Project; {Dialog is not displayed}
  390. end.
  391.